{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "P(X>r/2)=0.75\n"
     ]
    }
   ],
   "source": [
    "#例2-3，2-4\n",
    "from matplotlib import pyplot as plt\n",
    "import numpy as np\n",
    "def cdf(x, r):\n",
    "    if type(x)!=type(np.array([])):\n",
    "        x=np.array([x])\n",
    "    y=np.zeros(x.size)\n",
    "    d=np.where((x>=0)&(x<=r))\n",
    "    y[d]=(x[d]/r)**2\n",
    "    d=np.where(x>r)\n",
    "    y[d]=1\n",
    "    if y.size==1:\n",
    "        return y[0]\n",
    "    return y\n",
    "x1=np.linspace(-0.5, 2.5, 256)\n",
    "r=2\n",
    "y=cdf(x1, 2)\n",
    "plt.plot(x1, y)\n",
    "plt.xticks([0,2],[0.0, '$r$'])\n",
    "plt.yticks([0,0.5,1],[0.0, 0.5, 1.0])\n",
    "plt.show()\n",
    "print('P(X>r/2)=%.2f'%(1-cdf(x=1, r=2)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAD6CAYAAACxrrxPAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAawElEQVR4nO3dd3SUZcKG8eshlRZqILQQeq9JaK4dFXEVu6AgSEIAxba69rWX1f30s4sobEJvimJZXfuqWDIh1NBCDy0JJZCE1Hm+P2T3YzFAgEneKffvHI+EjOQ+mrnOOJnnHWOtRUREfF8NpweIiIhnKOgiIn5CQRcR8RMKuoiIn1DQRUT8RLBTX7hx48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T0VvtiUg1MsZsMcasNMYsM8a4nN7jTSp1PXQ/5LE3vhYRR5xvrdV98RiB+gjdY298LSLiLQI16HrjaxHfZYF/GmPSjDFJTo/xJoEadL3xtYjvOsta25ffXtRwmzHmHKcHeYuADLq1tgz49xtfrwHm//uNr40xVxy52VSg0ZE3vv4T8LuXNopI9bPW7jzy92xgEb+9yEHQ0X8R8SHGmNpADWvtoSO//gJ40lr7mcPTvEKgvspFRHxTU2DRkVcQBwOzFfP/p0foIiJ+IiCfQxcR8UcKuoiIn1DQRUT8hIIuIuInFHQRET+hoIuI+AkFXUTET/wfp6HvYUKhH+oAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "P(1<X<=3)=0.40\n"
     ]
    }
   ],
   "source": [
    "#练习2-2\n",
    "from matplotlib import pyplot as plt\n",
    "import numpy as np\n",
    "def cdf(x):\n",
    "    if type(x)!=type(np.array([])):\n",
    "        x=np.array([x])\n",
    "    y=np.zeros(x.size)\n",
    "    d=np.where((x>=0)&(x<=5))\n",
    "    y[d]=x[d]/5\n",
    "    d=np.where(x>5)\n",
    "    y[d]=1\n",
    "    if y.size==1:\n",
    "        return y[0]\n",
    "    return y\n",
    "x1=np.linspace(-0.5, 6, 256)\n",
    "r=2\n",
    "y=cdf(x1)\n",
    "plt.plot(x1, y)\n",
    "plt.xticks([0,5],[0.0, '$5$'])\n",
    "plt.yticks([0,0.5,1],[0.0, 0.5, 1.0])\n",
    "plt.show()\n",
    "print('P(1<X<=3)=%.2f'%(cdf(x=3)-cdf(x=1)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0.51, 0.49])"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#例2-17\n",
    "from scipy.stats import bernoulli\n",
    "import numpy as np\n",
    "x=bernoulli.rvs(loc=2, p=1/2,size=500)\n",
    "hist, _=np.histogram(x, bins=2)\n",
    "hist/500"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0.988, 0.012])"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#练习2-13\n",
    "from scipy.stats import bernoulli\n",
    "import numpy as np\n",
    "x=bernoulli.rvs(loc=2, p=0.01,size=500)\n",
    "hist, _=np.histogram(x, bins=2)\n",
    "hist/500"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "P(X>=30)=1-F(29)=0.9714\n"
     ]
    }
   ],
   "source": [
    "#例2-18，练习2-14\n",
    "from scipy.stats import geom\n",
    "p=geom.sf(29, 0.001)\n",
    "#prob=1-geom.cdf(k=29, p=0.001)\n",
    "print('P(X>=30)=1-F(29)=%.4f'%p)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "P(X<=5)=F(5)=0.6160\n"
     ]
    }
   ],
   "source": [
    "#例2-19\n",
    "from scipy.stats import binom\n",
    "prob=binom.cdf(k=5, n=5000, p=0.001)\n",
    "print('P(X<=5)=F(5)=%.4f'%prob)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "P(X>=6)=0.8115\n"
     ]
    }
   ],
   "source": [
    "#练习2-15\n",
    "from scipy.stats import binom\n",
    "#pro=1-binom.cdf(5, 400, 0.02)\n",
    "pro=binom.sf(5, 400, 0.02)\n",
    "print('P(X>=6)=%.4f'%pro)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "P(X=0)=0.2231\n",
      "P(X>=1)=0.9179\n"
     ]
    }
   ],
   "source": [
    "#例2-20\n",
    "from scipy.stats import poisson\n",
    "prob1=poisson.pmf(k=0, mu=1.5)\n",
    "prob2=poisson.sf(k=0, mu=2.5)\n",
    "print('P(X=0)=%.4f'%prob1)\n",
    "print('P(X>=1)=%.4f'%prob2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "P(X>=3)=0.0474\n"
     ]
    }
   ],
   "source": [
    "#练习2-16\n",
    "from scipy.stats import poisson\n",
    "lamd=0.8\n",
    "prob=poisson.sf(k=2, mu=0.8)\n",
    "print('P(X>=3)=%.4f'%prob)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "P(X<=13)≥0.998\n"
     ]
    }
   ],
   "source": [
    "#例2-21\n",
    "from scipy.stats import poisson\n",
    "lamd=5\n",
    "p=0.999\n",
    "x=poisson.ppf(q=p, mu=lamd)\n",
    "print('P(X<=%.0f)≥0.998'%x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "P(A)=0.3333\n"
     ]
    }
   ],
   "source": [
    "#例2-28\n",
    "from scipy.stats import uniform\n",
    "F=uniform.cdf\n",
    "print('P(A)=%.4f'%(F(15, scale=30)-#F(15)\n",
    "                   F(10, scale=30)+#F(10)\n",
    "                   F(30, scale=30)-#F(30)\n",
    "                   F(25, scale=30)))#F(25)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "P(950<X<=1059)=0.50\n"
     ]
    }
   ],
   "source": [
    "#练习2-22\n",
    "from scipy.stats import uniform\n",
    "F=uniform.cdf\n",
    "print('P(950<X<=1059)=%.2f'%(F(1050, loc=900, scale=200)-\n",
    "                             F(950, loc=900, scale=200)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "P(X>3)=0.3679\n",
      "P(3<=X<=6)=0.2325\n"
     ]
    }
   ],
   "source": [
    "#例2-29\n",
    "from scipy.stats import expon\n",
    "prob1=expon.sf(x=3, scale=3)\n",
    "prob2=expon.cdf(x=6, scale=3)-expon.cdf(x=3, scale=3)\n",
    "print('P(X>3)=%.4f'%prob1)\n",
    "print('P(3<=X<=6)=%.4f'%prob2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "P(50≤X≤150)=0.3834\n",
      "P(X<100)=0.6321\n"
     ]
    }
   ],
   "source": [
    "#练习2-23\n",
    "from scipy.stats import expon\n",
    "F=expon.cdf\n",
    "print('P(50≤X≤150)=%.4f'%(F(150, scale=100)-\n",
    "                          F(50, scale=100)))\n",
    "print('P(X<100)=%.4f'%F(100, loc=0, scale=100))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "P(𝜇-𝜎≤X≤𝜇+𝜎)=0.6827\n",
      "P(𝜇-2𝜎≤X≤𝜇+2𝜎)=0.9545\n",
      "P(𝜇-3𝜎≤X≤𝜇+3𝜎)=0.9973\n"
     ]
    }
   ],
   "source": [
    "#例2-30\n",
    "from scipy.stats import norm\n",
    "import numpy as np\n",
    "p1=2*norm.cdf(1)-1\n",
    "p2=2*norm.cdf(2)-1\n",
    "p3=2*norm.cdf(3)-1\n",
    "print('P(𝜇-𝜎≤X≤𝜇+𝜎)=%.4f'%p1)\n",
    "print('P(𝜇-2𝜎≤X≤𝜇+2𝜎)=%.4f'%p2)\n",
    "print('P(𝜇-3𝜎≤X≤𝜇+3𝜎)=%.4f'%p3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "P(|X-10.05|≥0.12)=0.0455\n"
     ]
    }
   ],
   "source": [
    "#练习2-24\n",
    "from scipy.stats import norm\n",
    "prob=1-norm.cdf(x=10.17, loc=10.05, scale=0.06)+norm.cdf(x=9.93, loc=10.05, scale=0.06)\n",
    "print('P(|X-10.05|≥0.12)=%.4f'%prob)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "x₁≤scor is True\n",
      "x₂≤scor is True\n"
     ]
    }
   ],
   "source": [
    "#例2-31\n",
    "from scipy.stats import norm\n",
    "mu=166\n",
    "scor=256\n",
    "p1=31/1657\n",
    "p2=300/1657\n",
    "p3=280/1657\n",
    "x=norm.isf(p1)\n",
    "sigma=(360-mu)/x\n",
    "x1=norm.isf(p2, mu, sigma)\n",
    "x2=norm.isf(p3, mu, sigma)\n",
    "print('x₁≤scor is %s'%(x1<=scor))\n",
    "print('x₂≤scor is %s'%(x2<=scor))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "P(2<X≤5)=0.5328\n",
      "P(-4<X≤10)=0.9995\n",
      "P(|X|>2)=0.6977\n",
      "c=3.0000\n",
      "d≥0.4369\n"
     ]
    }
   ],
   "source": [
    "#练习2-25\n",
    "from scipy.stats import norm\n",
    "mu=3\n",
    "sigma=2\n",
    "F=norm.cdf\n",
    "S=norm.sf\n",
    "p1=F(x=5, loc=mu, scale=sigma)-F(x=2, loc=mu, scale=sigma)\n",
    "p2=F(x=10, loc=mu, scale=sigma)-F(x=-4, loc=mu, scale=sigma)\n",
    "p3=F(x=-2, loc=mu, scale=sigma)+S(x=2, loc=mu, scale=sigma)\n",
    "c=norm.ppf(q=1/2, loc=mu, scale=sigma)\n",
    "d=norm.isf(q=0.9, loc=mu, scale=sigma)\n",
    "print('P(2<X≤5)=%.4f'%p1)\n",
    "print('P(-4<X≤10)=%.4f'%p2)\n",
    "print('P(|X|>2)=%.4f'%p3)\n",
    "print('c=%.4f'%c)\n",
    "print('d≥%.4f'%d)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 1.    2.   10.  ]\n",
      " [ 0.15  0.55  0.3 ]]\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAD4CAYAAAD8Zh1EAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAOz0lEQVR4nO3df6zd9V3H8eert4J2HeLs1cy29KI2aplT9MqmS3AMTEpw7RK3BNKNsWAak9Whm9FODCYYEjbNpsnIsrqhQ+/WTVxi3SqoG4b4x0gvY9lWkKyptL0y5SJjFYmwsrd/3AM7vZz2fm85l3Pvh+cjIT3f7/nk+31zQp987/l1U1VIkla+VaMeQJI0HAZdkhph0CWpEQZdkhph0CWpEatHdeJ169bVxMTEqE4vSSvSvffe+2hVjQ+6b2RBn5iYYHp6elSnl6QVKcmRU93nUy6S1AiDLkmNMOiS1AiDLkmNMOiS1AiDLkmNMOiS1AiDLkmNMOhnYGpqiomJCVatWsXExARTU1OjHkmSRvdJ0ZVq3Rt/h8fu+BB14ikAjhw5wtuuuZbr9t7H2gsuWbLzPnTzFUt2bElt8Ap9kR6/+7bnYv6sOvEUj99924gmkqQ5Bn2Rnjn+6KL2S9KL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8xNw3cb4hyV+PdqSRmgFmqurZn9huZy7wL1WXAf9eVbNV9W3gM8AvjXimUfuvJK8E6P35yLAObNDPQO+rgT8GPFBVHxj1PKNUVe+tqg1VNcHci11fqKqX7BVYVf0ncCzJT/R2XQrcP8KRRu0o8Noka3p/by7lJfwicU//V6W8Hfi7YR24y7ct6vleB7wN+GqSL/f2/X5V7R/hTFo+fhOY6n330WHgHSOeZ2Sq6p4ktwNfYu7dYffxEvoagCSfBF4PrEsyA/whcDPw6STXMvc/vLcM7Xx+9F+S2uBTLpLUCIMuSY0w6JLUCIMuSY0w6JLUCIMuSY0w6JLUiP8HvpF8nCM+XCMAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "#例2-37，2-38\n",
    "from matplotlib import pyplot as plt\n",
    "from scipy.stats import rv_discrete\n",
    "import numpy as np\n",
    "from utility import distCalcu\n",
    "X=np.array([-3, -1, 0, 1, 3])\n",
    "P=np.array([0.05, 0.2, 0.15, 0.35, 0.25])\n",
    "X=X**2+1\n",
    "(Y, P)=distCalcu(X, P)\n",
    "print(np.stack((Y, P)))\n",
    "mydist=rv_discrete(values=(Y, P))\n",
    "data=mydist.rvs(size=200)\n",
    "plt.hist(data, density=True)\n",
    "plt.plot(Y, mydist.pmf(Y), 'ko')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[-1.   1.   3.   5. ]\n",
      " [ 0.3  0.4  0.1  0.2]]\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAD8CAYAAABn919SAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xL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SjcDDwGeGnWWlW7WF3oB+r1RYleXRork3hr4L+Mpwkyzd3GWKF4HXgC9W1Wo9ln8D/DPgG8MOMgAF/NckL8y9CmWgujz6PzRJfh34831WPVZVv3K78wxYp9cl6PZLshb4T8A/qarLw86zVFV1DXhnknXAF5J8b1Wtqu9zJPlbwGtV9UKS9w47zwC8p6ouJPlO4ItJ/nDub7gDsaILvaoeGnaGZdTllQq6zZJ8G7Nl/mxV/edh5xmEqrqU5DeY/T7Hqip04D3AI0n+JvDtwH1JfqGqfmTIuZakqi7M/fO1JF9g9tLrwArdSy7D0+WVCrqN5l75/LPAy1X1M8POcyuSjM6dmZPkTwEPAX843FSLV1Ufr6qNVbWF2f9GvrRayzzJvUne/tZn4G8w4P/BrtpCT/J3kkwBfw14LsnxYWdajKqaAd56pcLLwOeqanK4qZYmyS8CvwV8T5KpJB8ZdqYleg/wD4AfnLut7MW5M8PV6LuAE0m+yuzJwxeralXf8teAPwf8ZpLfA34beK6qnh/kDnz0X5IasWrP0CVJ17PQJakRFrokNcJCl6RGWOiS1AgLXZIaYaFLUiP+H0CFynZ7KifQAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "#练习2-31\n",
    "import numpy as np\n",
    "from utility import distCalcu\n",
    "X=np.array([-1, 0, 1, 2])\n",
    "P=np.array([0.3, 0.4, 0.1, 0.2])\n",
    "Y=2*X+1\n",
    "Y1, P1=distCalcu(Y, P)\n",
    "print(np.stack((Y1, P1)))\n",
    "mydist=rv_discrete(values=(Y1, P1))\n",
    "data=mydist.rvs(size=200)\n",
    "plt.hist(data, density=True)\n",
    "plt.plot(Y1, mydist.pmf(Y1), 'ko')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAA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6jqjtC/cPdX6ztPmIV0Y20Jhpm1AF4CfuLuBUHnqQ13LwMGm1ky8C8zO97do+pYh5mdD2x390VmNiroPGFyqrvnmVl74B0zW1XxL90ai+hCd/cxQWeoQ6HcfFsCYGZNOFzmz7n7y0HnCRd332Nm73P4WEdUFTpwKjDOzM4FEoBWZvasu18ecK4ac/e8iv9uN7N/cXgatlaFrimX4IRy822pZ2ZmHL5H7kp3/1PQeWrLzFIqRuaYWTNgDLAq2FTHzt3vdPdUd+/O4c/Ke9Fc5maWaGYtv/gaOIsw/CUbtYVuZt82s1xgJPCGmc0JOtOxcPdS4Iubb68EZrp7ZrCpas7MpgOfAH3NLNfMJgWdqYZOBa4AzqhYTvZZxagwWnUC5prZMg4PIt5x96hf8hcDOgAfmdlSYAHwhru/VdsX1an/IiIxImpH6CIi8t9U6CIiMUKFLiISI1ToIiIxQoUuIhIjVOgiIjFChS4iEiP+DxyF+z+WQq0qAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "#例2-39\n",
    "from scipy.stats import rv_continuous\n",
    "import numpy as np\n",
    "from matplotlib import pyplot as plt\n",
    "class xdist(rv_continuous):\n",
    "    def _cdf(self, x, r):\n",
    "        y=np.zeros(x.size)\n",
    "        d=np.where((x>=0)&(x<=r))\n",
    "        y[d]=((x[d])/r[d])**2\n",
    "        d=np.where(x>r)\n",
    "        y[d]=1\n",
    "        return y\n",
    "dist1=xdist()\n",
    "x=np.arange(-1, 5, 0.05)\n",
    "plt.plot(x, dist1.cdf(x, 4))\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAD4CAYAAAD8Zh1EAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0R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1lm7XKfsXt2ZWZpQKXAf8IepZkpkDfX0Wl2HEZGonMzFoDXYBvg52k6souUcwG8oCP3D1ujwV4BrgPKAl6kAhw4EMzm1VWbB83FOj7C6vwWoJjZg2AScBd7r4t6Hmqyt2L3b0zpT293c0sLi+JmdnlQJ67zwp6lgg50927ApcAQ8ouW8YFBfr+winFloCUXW+eBGS4++Sg54kEd98CfAb0CniUqjoTuKLs2vM44HwzGx3sSFXn7qvL/psHvEnpZdi4oEDfXzil2BKAsh8kvgJ85+5/DXqe6jCzZmbWpOzxEcCFwMJgp6oad3/Q3VPdvTWl3y+fuHv/gMeqEjOrX/YDd8ysPnAxEDd3iCnQy3H3ImBvKfZ3wAR3XxDsVFVnZmOBb4CTzCzXzG4JeqZqOBO4kdIzwNllvy4NeqgqOhb41MzmUnoS8ZG7x/XtfgmiBfCVmc0BpgPvuvv7Ac8UNt22KCKSIHSGLiKSIBToIiIJQoEuIpIgFOgiIglCgS4ikiAU6CIiCUKBLiKSIP4Ph23mY8aZZ0EAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "#练习2-32\n",
    "from scipy.stats import rv_continuous\n",
    "import numpy as np\n",
    "from matplotlib import pyplot as plt\n",
    "class xdist(rv_continuous):\n",
    "    def _cdf(self, x):\n",
    "        y=np.zeros(x.size)\n",
    "        d=np.where((x>=0)&(x<=5))\n",
    "        y[d]=(x[d])/5\n",
    "        d=np.where(x>5)\n",
    "        y[d]=1\n",
    "        return y\n",
    "dist1=xdist()\n",
    "x=np.arange(-0.5, 5.5, 0.05)\n",
    "plt.plot(x, dist1.cdf(x))\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "P(0<X<1)=0.50\n"
     ]
    }
   ],
   "source": [
    "#例2-40\n",
    "from scipy.stats import rv_continuous\n",
    "import numpy as np\n",
    "class mydist(rv_continuous):\n",
    "    def _pdf(self, x):\n",
    "        if type(x)!=type(np.array([])):\n",
    "            x=np.array([x])\n",
    "        y=np.zeros(x.size)\n",
    "        d=np.where((x<1)&(x>-1))\n",
    "        y[d]=1/(np.pi*(np.sqrt((1-x[d]**2))))\n",
    "        if y.size==1:\n",
    "            return y[0]\n",
    "        return y\n",
    "dist=mydist()\n",
    "p=dist.cdf(1)-dist.cdf(0)\n",
    "print('P(0<X<1)=%.2f'%p)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "P(1<X<7/2)=0.85\n"
     ]
    }
   ],
   "source": [
    "#练习2-33\n",
    "from scipy.stats import rv_continuous\n",
    "import numpy as np\n",
    "class mydist(rv_continuous):\n",
    "    def _pdf(self, x):\n",
    "        if type(x)!=type(np.array([])):\n",
    "            x=np.array([x])\n",
    "        y=np.zeros(x.size)\n",
    "        d=np.where((x>=0)&(x<3))\n",
    "        y[d]=x[d]/6\n",
    "        d=np.where((x>=3)&(x<4))\n",
    "        y[d]=2-x[d]/2\n",
    "        if y.size==1:\n",
    "            return y[0]\n",
    "        return y\n",
    "dist=mydist()\n",
    "p=dist.cdf(7/2)-dist.cdf(1)\n",
    "print('P(1<X<7/2)=%.2f'%p)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXoAAAD4CAYAAADiry33AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAf/klEQVR4nO3deZwU5bn28d/d3QNGcUEYDQIJCuoRxXXEcNxIcIFIRCMaMDGak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/J/8DiwGTmruZ4fGzPYDHgHmAVF584+J+9jBf4ZrOb7xdMFnqKAXEUk5tW5ERFJOQS8iknIKehGRlFPQi4iknIJeRCTlFPQiIimnoBcRSbn/D+6HLgzRVd0NAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "#例2-41\n",
    "from scipy.stats import uniform, rv_continuous\n",
    "import numpy as np\n",
    "from matplotlib import pyplot as plt\n",
    "def h(y):\n",
    "    x=np.zeros(y.size)\n",
    "    d=np.where(y>=0)\n",
    "    x[d]=2*np.sqrt(y[d]/np.pi)\n",
    "    return x\n",
    "class ydist(rv_continuous):\n",
    "    def _cdf(self, y, a, b):\n",
    "        return uniform.cdf(h(y), loc=a, scale=b-a)\n",
    "dist=ydist()\n",
    "x=np.linspace(-2, 25, 256)\n",
    "a, b=2, 5\n",
    "v=dist.rvs(a, b, size=200)\n",
    "plt.hist(v, density=True)\n",
    "y=dist.pdf(x,a,b)\n",
    "plt.plot(x,y)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYAAAAD4CAYAAADlwTGnAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAgAElEQVR4nO3de5ScdZ3n8fe3qvp+yaU7F0iQJIRbwiVgJoI4HiUcEoU1nl1YA+MsznAO64ouDDOHhZnRGdlhFd2zMLuAioKHYVghojNGRFEBHdE1kJAEzI00SYBASAc66aTvqarv/lFPdaor1Z1Oup+qp7o+r5M6/dRzqf49nar6Pp/n99SvzN0REZHKEyt1A0REpDRUAEREKpQKgIhIh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yKzJv/o+7+w2D2XjM7yd33BKd42oP5E+FvcQnwCTP7OFALNJNJBJPNLBEc5efuV3afd+cNgVM+St0JMVFvwC6OdAJfwdAOsheC+VOBnWQ6gKcE01NL3fbj3M/lZD7pPS1v/kKGdgLvINNpmgim53Kk43RhqffjBPd9wuxLgX0z4J+Ae/Lmf52hncBfC6YLPsfL9UbmwCzbCfx9hnYCfy6YvpGhncCrSt3u470pARTHU2SukmgDeoA/A3D3DjP772TGRgK4w93L6wgC7iXzJv+LIPn83t0/6xUwDIgPM0xKiZs1Xi4B/hR4xcw2BPP+GvgqsMrMrgfeAK4OlhV8jk8Q/w14zMz+AVhPZugbGGYInHKioSBERCqUrgISEalQKgAiIhVKBUBEpEKpAIiIVCgVABGRCqUCICJSoVQAREQq1P8HiNS3yX2lbTcAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "#练习2-34\n",
    "from scipy.stats import rv_continuous\n",
    "import numpy as np\n",
    "from matplotlib import pyplot as plt\n",
    "class vdist(rv_continuous):\n",
    "    def _cdf(self, v):\n",
    "        y=np.zeros(v.size)\n",
    "        d=np.where((v>-380)&(v<380))\n",
    "        y[d]=np.arcsin(v[d]/380)/np.pi+1/2\n",
    "        d=np.where(v>=380)\n",
    "        y[d]=1\n",
    "        return y\n",
    "dist=vdist()\n",
    "v=np.linspace(-500,500, 256)\n",
    "plt.plot(v, dist.pdf(v), color='black')\n",
    "V=dist.rvs(size=10000)\n",
    "plt.hist(V, density=True, histtype='stepfilled')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
